#include "HelloWorldScene.h"
USING_NS_CC;

Scene* HelloWorld::createScene()
{
    // 'scene' is an autorelease object
    auto scene = Scene::create();
    
    // 'layer' is an autorelease object
    auto layer = HelloWorld::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    MenuItem* newGameItem = MenuItemImage::create(
    		"image/button_blank_02.png",
    		"image/button_blank_02_h.png",
    		this,
    		menu_selector(HelloWorld::newGameHandle));
    CCLabelTTF* label = CCLabelTTF::create("New Game","Arial",16);
    newGameItem->addChild(label);
    label->setPosition(newGameItem->getContentSize().width/2 ,newGameItem->getContentSize().height/2);
    cocos2d::Menu* pMenu = cocos2d::Menu::create(newGameItem, NULL);

    this->addChild(pMenu,1);
    
    return true;
}
void HelloWorld::newGameHandle(Ref* pSender){
	auto scene = GameScene::createScene();
	CCDirector::sharedDirector()->replaceScene(scene);
}

void HelloWorld::menuCloseCallback(Ref* pSender)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
	MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
    return;
#endif

    Director::getInstance()->end();

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    exit(0);
#endif
}
